<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>各部门需求处理子页面</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<style type="text/css">
.datagrid-btable .datagrid-cell{padding:6px 4px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;} 
}
</style>
<script type="text/javascript">
	$(function() {
		//默认审批申请对话框是关闭的
		$('#shenpishenqing').dialog('close');
		//配置数据表格，显示申请数据
		$('#showMsg').datagrid({
			url : '${pageContext.request.contextPath}/xianshiApplication',
			columns : [ [ {
				field : 'checked',
				checkbox : true,
				width : 90
			}, {
				field : 'maId',
				title : '申请编号',
				width : 90,
				hidden : false
			}, {
				field : 'createDate',
				title : '创建日期',
				width : 90
			}, {
				field : 'elName',
				title : '申请人',
				width : 90
			}, {
				field : 'dName',
				title : '申请所属部门',
				width : 90
			}, {
				field : 'money',
				title : '申请金额',
				width : 90,
			}, {
				field : 'state',
				title : '审批状态',
				width : 90,
			}, {
				field : 'aContent',
				title : '申请内容',
				width : 90,
				formatter: function(value,row,index){
					 return '<span title='+value+'>'+value+'</span>';  
				}
			}, ] ],
			pagination : true, //显示分页
			striped : true,
			rownumbers : true,
			singleSelect : true,
		//禁止多选
		});
		//配置搜索框
		$('#searchAppl').searchbox({
			searcher : function(value, name) {
				var Name = value;
				//如果搜索名不为空，则隐藏导出按钮，并设置好审批申请按钮的位置(因为导出的是所有datagrid的数据)
				if (Name != null) {
					$('#daochu').hide();
					$('#shenpiButton').attr("style", "margin-left: 410px;");

				}
				//当搜索名为空时,显示导出按钮，审批申请按钮的位置还原
				if (Name == "") {
					$('#daochu').show();
					$('#shenpiButton').attr("style", "margin-left: ");
				}
				$('#fenleichakanCombobox').combobox("setValue", "按状态查看");
				$('#showMsg').datagrid('reload', {
					searchName : Name,
				});
			}
		});
		//分类查看
		$('#fenleichakanCombobox').combobox({
			onSelect : function(record) {
				var fenlei = $('#fenleichakanCombobox').combobox("getValue");
				if (fenlei != "") {
					$('#daochu').hide();
					$('#shenpiButton').attr("style", "margin-left: 410px;");
				}
				$("#searchAppl").searchbox('clear');
				$('#showMsg').datagrid('reload', {
					fenlei1 : fenlei,
				});
			},
		});

		//配置审批申请表单
		$("#shenpiForm").form(
				{
					url : '${pageContext.request.contextPath}/shenpishenqing',
					success : function(data) {
						if (data == "1") {
							$.messager.alert('我的消息', '已批准', 'info', function() {
								$('#showMsg').datagrid('reload');
							});
							$('#shenpishenqing').dialog('close');
							$("#shenpiForm").form('clear');
						} else {
							if (data == "0") {
								$.messager.alert('我的消息', '已驳回申请', 'info',
										function() {
											$('#showMsg').datagrid('reload');
										});
								$('#shenpishenqing').dialog('close');
								$("#shenpiForm").form('clear');
							} else {
								$.messager.alert('我的消息', '审批失败，未知错误', 'info',
										function() {
											$('#showMsg').datagrid('reload');
										});
								$('#shenpishenqing').dialog('close');
								$("#shenpiForm").form('clear');
							}
						}
					}
				})  
		//设置结算日期为当前时间	
		formatterDate = function(date) {
			var day = date.getDate() > 9 ? date.getDate() : "0"
					+ date.getDate();
			var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
					+ (date.getMonth() + 1);
			return date.getFullYear() + '-' + month + '-' + day;
		};
		//点击审批申请，显示审批申请对话框
		$("#shenpiButton").click(
				function() {
					var stus = $("#showMsg").datagrid('getSelections'); //统计申请被选中的条数
					if (stus == 0) {
						$.messager.alert('我的消息', '请选择需要审批的申请', 'info',
								function() {
									$('#showMsg').datagrid('reload');
								});
					} else {
						//由于设置了不能多选，所以只有一条申请被选中
						var em11 = $("#showMsg").datagrid('getSelected');
						if (em11.state != "已提交") {
							$.messager.alert('我的消息', '该申请已审批过,请重新选择', 'info',
									function() {
										$('#showMsg').datagrid('reload');
									});
						} else {
							$('#shenpishenqing').dialog('open');//打开审批申请对话框
							var shenqing = stus[0];
							$('#shenpiForm').form('load', shenqing); //把勾选的申请数据读入对话框
						}

					}
					//把当前日期读到approveDate（审批日期）里
					$('#approveDate').datebox('setValue',
							formatterDate(new Date()));
					//把后台存在session中的后勤主管的名字读入相应的后勤主管文本框中
					$('#hqName').textbox('setValue', '${hqname}');
				});

		//设置分类查看下拉框的默认提示值
		$('#fenleichakanCombobox').combobox("setValue", "按状态查看");
		//点击导出按钮，提交form表单
		$('#daochu').click(function() {
			$('#DataGridDaochuForm').submit();
		})
	})

	/*	//导出事件
	 function daochu() {
	 $.ajax({
	 traditional:true,
	 url : '${pageContext.request.contextPath}/DataGridDaochu',
	 type : 'POST',
	 dataType : 'text',
	 success : function(data) {
	 if (data=="1") {
	 $.messager.alert('我的消息', '已导出数据到d://Test.xls', 'info', function() {
	 $('#showMsg').datagrid('reload');
	 });
	 } else {
	 alert("导出失败");
	 }  
	 },
	 });
	 }*/
	//配置审批表单提交事件
	function tijiaoshenpi() {
		$('#shenpiForm').form('submit');
	}
</script>
<body>
<form action="DataGridDaochu" method="post" id="DataGridDaochuForm" style="display: none;"></form>
    <!-- 模糊查询 -->
    <div style="display: inline;">
	<input style="display: block;" id="searchAppl" class="easyui-searchbox" data-options="prompt:'输入姓名或部门名查询',width:150">
    <!-- 分类查看下拉框 -->
    <select class="easyui-combobox" name="fenleichakan"  panelHeight="100" id="fenleichakanCombobox" style="width:90px;" onSelect="fenleichakan()" data-options="editable:false">
                <option value="已提交">已提交</option>   
			    <option value="已通过">已通过</option>   
			    <option value="未通过">未通过</option>  
			    <option value="已回复">已回复</option>
	</select> 
    <!-- 导出按钮 -->
    <button id="daochu" onclick="daochu()" type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off" style="margin-left: 350px;">
                     导出
    </button>
    <!-- 审批按钮 -->
	<button id="shenpiButton" type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off">
                     审批申请
    </button>
    </div>
    <!-- 显示界面 -->
	<table id="showMsg"></table>
	<!-- 审批申请对话框 -->
	<div id="shenpishenqing" class="easyui-dialog" title="申请内容信息"
		style="width: 400px; height: 450px;" data-options="modal:true">
		<form id="shenpiForm" method="post">
			<div style="margin-bottom: 20px;">
				<span>申请编号</span> <input class="easyui-textbox" name="maId" id="maId" readonly="readonly"
					style="width: 100%;">
			</div>
			<div style="margin-bottom: 20px">
				<span>后勤主管</span> <input class="easyui-textbox" name="hqName" id="hqName" readonly="readonly"
					style="width: 100%" data-options="">
			</div>
			<div style="margin-bottom: 20px">
				<span>申请人</span> <input class="easyui-textbox" name="elName" id="elName" readonly="readonly"
					style="width: 100%" data-options="">
			</div>
			<div style="margin-bottom: 20px">
				<span>申请金额</span> <input class="easyui-textbox" name="money" id="money" readonly="readonly"
					style="width: 100%" data-options="">
			</div>
			<div style="margin-bottom: 20px">
				<span>审批日期</span> <input class="easyui-datebox" name="approveDate" id="approveDate" readonly="readonly"
					style="width: 100%" data-options="">
			</div>
			<!-- 配置下拉框,来审批申请："通过"或者"未通过" -->

			<select class="easyui-combobox" name="dept" style="width:386px;" panelHeight="50" data-options="editable:false">   
			    <option value="已通过">同意审批</option>   
			    <option value="未通过">拒绝申请</option>    
			</select> 
		   <div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="tijiaoshenpi()" style="width: 80px">确定</a>
		</div>
		</form>
	</div>
</body>
</html>